#include "TeachersTable.h"
#include "Ext\FilterQuery.h"

namespace TCServer
{
    namespace Store
    {
        QList<QVariantMap> TeachersTable::query(quint64 groupId, uint index, uint number)
        {
            FilterQuery q;
            q.prepare(R"(

            SELECT `id`,
                `groupId`,
                `subject`,
                `name`,
                `head`,
                `unit`,
                `level`,
                `school`,
                `major`,
                `detail`,
                `time`
            FROM `tc`.`p2pteachers`
            WHERE `id` IN (SELECT * FROM (
                SELECT `id` FROM `tc`.`p2pteachers` 
                ORDER BY `id` ASC
                LIMIT ?, ?
            ) as ids)
            AND `groupId` = ?;

            )");
            q.addBindValue(index);
            q.addBindValue(number);
            q.addBindValue(groupId);


            QList<QVariantMap> res;
            q.exec();

            while (q.next())
            {
                res.append(
                {
                    { "id", q.nextValue().toULongLong() },
                    { "groupId", q.nextValue().toULongLong() },
                    { "subject", q.nextValue().toUInt() },
                    { "name", q.nextValue().toString() },
                    { "head", q.nextValue().toString() },
                    { "unit", q.nextValue().toString() },
                    { "level", q.nextValue().toUInt() },
                    { "school", q.nextValue().toString() },
                    { "major", q.nextValue().toString() },
                    { "detail", q.nextValue().toString() },
                    { "time", q.nextValue().toDateTime() },
                });
            }
            return res;
        }
    }
}